import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  ParseUUIDPipe,
} from '@nestjs/common';
import { CompanyService } from './company.service';
import { CreateCompanyDto } from './dto/create-company.dto';
import { UpdateCompanyDto } from './dto/update-company.dto';
import {ApiOkResponse, ApiTags} from '@nestjs/swagger';
import { companyEntity } from './entities/company.entity';
@ApiTags('company')
@Controller('company')
export class CompanyController {
  constructor(private readonly companyService: CompanyService) {}

  @Post()
  async create(@Body() createCompanyDto: CreateCompanyDto) {
    return new companyEntity(
      await this.companyService.create(createCompanyDto),
    );
  }

  @Get()
  @ApiOkResponse({ type: companyEntity })
  async findAll() {
    const companies = await this.companyService.findAll();
    return companies.map((company) => new companyEntity(company));
  }

  @Get(':id')
  async findOne(@Param('id', ParseUUIDPipe) id: string) {
    return new companyEntity(await this.companyService.findOne(id));
  }

  @Patch(':id')
  async update(
    @Param('id', ParseUUIDPipe) id: string,
    @Body() updateCompanyDto: UpdateCompanyDto,
  ) {
    return new companyEntity(
      await this.companyService.update(id, updateCompanyDto),
    );
  }

  @Delete(':id')
  async remove(@Param('id', ParseUUIDPipe) id: string) {
    return new companyEntity(await this.companyService.remove(id));
  }
}
